package Advance.Lock;
/*
 * Description:原子锁，确保不会同时存在两个线程修改同一个信息。
 * Author: AMark
 * Date:11/15/2023
 * Time:9:38 AM
 */
class bank{
    private int balance = 100;
    public int getBalance(){
        return this.balance;
    }
    public synchronized void save1(int money) {
        balance = balance + money;
    }
    public void save2(int money) {
        synchronized (this) {
            balance = balance + money;
            System.out.println(Thread.currentThread().getName() + "存入" + money + "元" + "账户余额" + this.getBalance());
        }
    }

    
}
public class SynchronizedDemo implements Runnable{
    @Override
    public void run() {

    }


}
